package com.example.purplestarcb.shoujizhushou;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

/**
 * 自定义组合控件
 * Created by PurpleStarCB on 2015/3/21.
 */
public class SettingItemView extends RelativeLayout {
    private ToggleButton tbStatus;
    private TextView tvDesc;
    private TextView tvTitle;
    private String desc_on;
    private String desc_off;
    public SettingItemView(Context context) {
        super(context);
        iniView(context);
    }

    public SettingItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        iniView(context);
        String titlel=attrs.getAttributeValue("http://schemas.android.com/apk/com.example.purplestarcb.shoujizhushou","titlel");
        desc_on=attrs.getAttributeValue("http://schemas.android.com/apk/com.example.purplestarcb.shoujizhushou","desc_on");
        desc_off=attrs.getAttributeValue("http://schemas.android.com/apk/com.example.purplestarcb.shoujizhushou","desc_off");
        tvTitle.setText(titlel);
        tvDesc.setText(desc_off);
    }

    public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        iniView(context);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        iniView(context);
    }

    /**
     * 初始化布局文件
     * @param context
     */
    private void iniView(Context context) {
        View.inflate(context,R.layout.setting_ite_view,this);
        tbStatus= (ToggleButton) this.findViewById(R.id.tb_status);
        tvDesc= (TextView) this.findViewById(R.id.tv_desc);
        tvTitle= (TextView) this.findViewById(R.id.tv_setting_titlel);
    }
    /**
     * 校验组合控件是否选中
     */
    public boolean isChecked(){


        return tbStatus.isChecked();
    }
    /**
     * 设置组合控件的状态
     */
    public void setChecked(boolean checked){
        if(checked){
            setDesc(desc_on);
        }else{
            setDesc(desc_off);
        }
        tbStatus.setChecked(checked);
    }
    /**
     * 组合空间描述信息
     */
    public void setDesc(String text){
        tvDesc.setText(text);
    }
}
